package com.miyake.loveviewweb.server;

import java.util.ArrayList;
import java.util.List;

import com.miyake.loveviewweb.shared.model.ValueModel;
import com.miyake.rest.Value;
import com.miyake.rest.Value.SubUnit;

public class ValueConverter {
    public List<ValueModel> webToModel(List<Value> values) {
        List<ValueModel> ret = new ArrayList<ValueModel>();
        
        for (Value value : values) {
            ret.add(new ValueModel(value.getId(), value.getCaption(), value.getValue(), value.getSubUnit().toString(), value.getUnit()));
        }
        return ret;   
    }
    
    public List<Value> modelToWeb(List<ValueModel> values) {
        List<Value> ret = new ArrayList<Value>();
        
        for (ValueModel valueModel : values) {
            ret.add(new Value(valueModel.getId(), valueModel.getCaption(), valueModel.getValue(), SubUnit.valueOf(SubUnit.class, valueModel.getSubUnit()), valueModel.getUnit()));
        }
        return ret;
    }
}
